#include "Handle.h"

using namespace Shared;

#ifdef __linux__

bool Shared::Handle::Avail()
{
    return handle;
}

bool Shared::Handle::Open(const char *path)
{
    handle = dlopen(path, RTLD_LAZY);
    return handle;
}

int Shared::Handle::Close()
{
    return dlclose(handle);
}
void *Shared::Handle::GetProjAddr(const char *funcName)
{
    return dlsym(handle, funcName);
}

std::string Shared::Handle::GetSharedPath(const std::string &name)
{
    return std::string("lib") + name + ".so";
};

#endif

#ifdef _WIN32

bool Shared::Handle::Avail()
{
    return handle;
}

bool Shared::Handle::Open(const char *path)
{
    handle = LoadLibrary(path);
    return handle;
}

void *Shared::Handle::GetProjAddr(const char *funcName)
{
    return GetProcAddress((HMODULE)handle, funcName);
}

int Shared::Handle::Close()
{
    return FreeLibrary((HMODULE)handle);
};

std::string Shared::Handle::GetSharedPath(const std::string &name)
{
    return name + ".dll";
};

#endif // _win_32
